home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-19 / gpt32src.zip / PC.TRM < prev    next >
Text File  |  1992-03-25  |  27KB  |  1,427 lines

  1. /*
  2.  * $Id: pc.trm,v 3.26 92/03/24 22:35:39 woo Exp Locker: woo $
  3.  */
  4.  
  5. /* GNUPLOT - pc.trm */
  6. /*
  7.  * Copyright (C) 1990, 1991, 1992
  8.  *
  9.  * Permission to use, copy, and distribute this software and its
  10.  * documentation for any purpose with or without fee is hereby granted, 
  11.  * provided that the above copyright notice appear in all copies and 
  12.  * that both that copyright notice and this permission notice appear 
  13.  * in supporting documentation.
  14.  *
  15.  * Permission to modify the software is granted, but not the right to
  16.  * distribute the modified code.  Modifications are to be distributed 
  17.  * as patches to released version.
  18.  *
  19.  * This software  is provided "as is" without express or implied warranty.
  20.  *
  21.  * This file is included by ../term.c.
  22.  *
  23.  * This terminal driver supports:
  24.  *  Under Microsoft C
  25.  *      cga, egabios, egalib, vgabios, hercules, corona325, att
  26.  *  Under Turboc C
  27.  *      egalib, vgalib, vgamono, svga, mcga, cga, hercules, att
  28.  *
  29.  * AUTHORS
  30.  *  Colin Kelley, Thomas Williams, William Wilson, Russell Lang
  31.  *
  32.  * send your comments or suggestions to (info-gnuplot@ames.arc.nasa.gov).
  33.  *
  34.  */
  35.  
  36. #ifdef __TURBOC__
  37. #include <graphics.h>
  38. #include <conio.h>
  39. #include <dos.h>
  40.   int g_driver, g_mode, g_error;
  41.   char far *path;
  42.   char *pathp, path_s[128];
  43.  
  44. /* instead of string.h */
  45. extern char *strrchr();
  46.  
  47. get_path()
  48. {
  49.    path=(char far *) getenv("BGI");
  50.    if (path==NULL) {
  51.       (void) strcpy(path_s,_argv[0]);
  52.       pathp=strrchr(path_s,'\\');
  53.       *pathp=0x00;
  54.       path=path_s;
  55.    }
  56. }
  57.  
  58. static struct text_info tinfo;       /* So we can restore starting text mode. */
  59. #endif
  60.  
  61.  
  62. static char near buf[80];    /* kludge since EGA.LIB is compiled SMALL */
  63.  
  64. static int pattern[] = {0xffff, 0x0f0f, 0xffff, 0xaaaa, 0x3333, 0x3f3f, 0x0f0f};
  65.  
  66. static int graphics_on = FALSE;
  67. int startx, starty;
  68.  
  69. int pc_angle;
  70. #define PC_VCHAR FNT5X9_VCHAR
  71. #define PC_HCHAR FNT5X9_HCHAR
  72.  
  73. pause()        /* press any key to continue... */
  74. {
  75.     (void) getch();
  76. }
  77.  
  78.  
  79. PC_text()
  80. {
  81.     if (graphics_on) {
  82.         graphics_on = FALSE;
  83.         pause();
  84.     }
  85. #ifdef __TURBOC__
  86.     restorecrtmode();
  87.         textmode(tinfo.currmode);
  88.     clrscr();
  89. #else
  90.     Vmode(3);
  91. #endif
  92. }
  93.  
  94. PC_reset()
  95. {
  96. #ifdef __TURBOC__
  97.     closegraph();
  98.         textmode(tinfo.currmode);
  99.     clrscr();
  100. #endif
  101. }
  102.  
  103.  
  104. #ifndef __TURBOC__
  105.  
  106. PC_putc(x,y,c,angle,line_func)
  107. unsigned int x,y;
  108. char c;
  109. int angle;
  110. FUNC_PTR line_func;
  111. {
  112. int i,j,k;
  113. unsigned int pixelon;
  114.     i = (int)(c) - 32;
  115.     for (j=0; j<FNT5X9_VBITS; j++) {
  116.         for (k=0; k<FNT5X9_HBITS; k++) {
  117.             pixelon = (((unsigned int)(fnt5x9[i][j])) >> k & 1);
  118.             if (pixelon) {
  119.                 switch(angle) {
  120.                     case 0 : (*line_func)(x+k+1,y-j,x+k+1,y-j);
  121.                             break;
  122.                     case 1 : (*line_func)(x-j,y-k-1,x-j,y-k-1);
  123.                             break;
  124.                 }
  125.             }
  126.         }
  127.     }
  128. }
  129.  
  130.  
  131. int PC_text_angle(ang)
  132. int ang;
  133. {
  134.     pc_angle=ang;
  135.     return TRUE;
  136. }
  137.  
  138.  
  139. #define CGA_XMAX 640
  140. #define CGA_YMAX 200
  141.  
  142. #define CGA_XLAST (CGA_XMAX - 1)
  143. #define CGA_YLAST (CGA_YMAX - 1)
  144.  
  145. #define CGA_VCHAR PC_VCHAR
  146. #define CGA_HCHAR PC_HCHAR
  147. #define CGA_VTIC 4
  148. #define CGA_HTIC 6
  149.  
  150. int line_cga;
  151.  
  152. CGA_init()
  153. {
  154.     PC_color(1);        /* monochrome */
  155. }
  156.  
  157. CGA_graphics()
  158. {
  159.     graphics_on = TRUE;
  160.     Vmode(6);
  161. }
  162.  
  163. #define CGA_text PC_text
  164.  
  165. CGA_linetype(linetype)
  166. {
  167.     if (linetype >= 5)
  168.         linetype %= 5;
  169.     line_cga=linetype;
  170.     PC_mask(pattern[linetype+2]);
  171. }
  172.  
  173. CGA_move(x,y)
  174. {
  175.     startx = x;
  176.     starty = y;
  177. }
  178.  
  179.  
  180. CGA_vector(x,y)
  181. {
  182.     PC_line(startx,CGA_YLAST-starty,x,CGA_YLAST-y);
  183.     startx = x;
  184.     starty = y;
  185. }
  186.  
  187.  
  188. CGA_put_text(x,y,str)
  189. unsigned int x, y;
  190. char *str;
  191. {
  192. int i;
  193. int line;
  194.     line= line_cga;     /* disable the dotted lines temporarily */
  195.     PC_mask(pattern[0]);
  196.     switch(pc_angle) {
  197.         case 0 : y -= CGA_VCHAR/2;
  198.                 break;
  199.         case 1 : x += CGA_VCHAR/2;
  200.                 break;
  201.     }
  202.     for (i=0;str[i];i++) {
  203.         PC_putc(x,CGA_YLAST-y,str[i],pc_angle,PC_line);
  204.         switch(pc_angle) {
  205.             case 0 : x+=CGA_HCHAR ;
  206.                     break;
  207.             case 1 : y+=CGA_HCHAR ;
  208.                     break;
  209.         }
  210.     }
  211.     PC_mask(pattern[line]);  /* enable dotted lines */
  212. }
  213.  
  214.  
  215. #define CGA_text_angle PC_text_angle
  216.  
  217. #define CGA_reset PC_reset
  218.  
  219.  
  220. #define EGA_XMAX 640
  221. #define EGA_YMAX 350
  222.  
  223. #define EGA_XLAST (EGA_XMAX - 1)
  224. #define EGA_YLAST (EGA_YMAX - 1)
  225.  
  226. #define EGA_VCHAR PC_VCHAR
  227. #define EGA_HCHAR PC_HCHAR
  228. #define EGA_VTIC 4
  229. #define EGA_HTIC 5
  230.  
  231. static int ega64color[] =  {1,1,5,4,3,5,4,3, 5, 4, 3, 5, 4, 3,5};
  232. static int ega256color[] = {7,8,2,3,4,5,9,14,12,15,13,10,11,1,6};
  233.  
  234. static int *egacolor;
  235.  
  236.  
  237. EGA_init()
  238. {
  239.     PC_mask(0xffff);
  240.     egacolor = ega256color;        /* should be smarter */
  241. }
  242.  
  243. EGA_graphics()
  244. {
  245.     graphics_on = TRUE;
  246.     Vmode(16);
  247. }
  248.  
  249. #define EGA_text PC_text
  250.  
  251. EGA_linetype(linetype)
  252. {
  253.     if (linetype >= 13)
  254.         linetype %= 13;
  255.     PC_color(egacolor[linetype+2]);
  256. }
  257.  
  258. EGA_move(x,y)
  259. {
  260.     startx = x;
  261.     starty = y;
  262. }
  263.  
  264. EGA_vector(x,y)
  265. {
  266.     PC_line(startx,EGA_YLAST-starty,x,EGA_YLAST-y);
  267.     startx = x;
  268.     starty = y;
  269. }
  270.  
  271.  
  272. EGA_put_text(x,y,str)
  273. unsigned int x, y;
  274. char *str;
  275. {
  276. int i;
  277.     switch(pc_angle) {
  278.         case 0 : y -= EGA_VCHAR/2;
  279.                 break;
  280.         case 1 : x += EGA_VCHAR/2;
  281.                 break;
  282.     }
  283.     for (i=0;str[i];i++) {
  284.         PC_putc(x,EGA_YLAST-y,str[i],pc_angle,PC_line);
  285.         switch(pc_angle) {
  286.             case 0 : x+=EGA_HCHAR ;
  287.                     break;
  288.             case 1 : y+=EGA_HCHAR ;
  289.                     break;
  290.         }
  291.     }
  292. }
  293.  
  294.  
  295. #define EGA_text_angle PC_text_angle
  296.  
  297. #define EGA_reset PC_reset
  298.  
  299.  
  300.  
  301. /* The following VGA routines are hacked from the above EGA routines
  302.    They worked on two VGA cards.
  303.    Russell Lang, eln272v@monu1.cc.monash.oz */
  304. #define VGA_XMAX 640
  305. #define VGA_YMAX 480
  306.  
  307. #define VGA_XLAST (VGA_XMAX - 1)
  308. #define VGA_YLAST (VGA_YMAX - 1)
  309.  
  310. #define VGA_VCHAR PC_VCHAR
  311. #define VGA_HCHAR PC_HCHAR
  312. #define VGA_VTIC 5
  313. #define VGA_HTIC 5
  314.  
  315. static int vga256color[] = {7,8,2,3,4,5,9,14,12,15,13,10,11,1,6};
  316.  
  317. static int *vgacolor;
  318.  
  319.  
  320. VGA_init()
  321. {
  322.     PC_mask(0xffff);
  323.     vgacolor = vga256color;        /* should be smarter */
  324. }
  325.  
  326. VGA_graphics()
  327. {
  328.     graphics_on = TRUE;
  329.     Vmode(18);
  330. }
  331.  
  332. #define VGA_text PC_text
  333.  
  334. VGA_linetype(linetype)
  335. {
  336.     if (linetype >= 13)
  337.         linetype %= 13;
  338.     PC_color(vgacolor[linetype+2]);
  339. }
  340.  
  341. VGA_move(x,y)
  342. {
  343.     startx = x;
  344.     starty = y;
  345. }
  346.  
  347. VGA_vector(x,y)
  348. {
  349.     PC_line(startx,VGA_YLAST-starty,x,VGA_YLAST-y);
  350.     startx = x;
  351.     starty = y;
  352. }
  353.  
  354.  
  355. VGA_put_text(x,y,str)
  356. unsigned int x, y;
  357. char *str;
  358. {
  359. int i;
  360.     switch(pc_angle) {
  361.         case 0 : y -= VGA_VCHAR/2;
  362.                 break;
  363.         case 1 : x += VGA_VCHAR/2;
  364.                 break;
  365.     }
  366.     for (i=0;str[i];i++) {
  367.         PC_putc(x,VGA_YLAST-y,str[i],pc_angle,PC_line);
  368.         switch(pc_angle) {
  369.             case 0 : x+=VGA_HCHAR ;
  370.                     break;
  371.             case 1 : y+=VGA_HCHAR ;
  372.                     break;
  373.         }
  374.     }
  375. }
  376.  
  377.  
  378. #define VGA_text_angle PC_text_angle
  379.  
  380. #define VGA_reset PC_reset
  381.  
  382.  
  383.  
  384. #ifdef EGALIB
  385.  
  386. #define EGALIB_XMAX 640
  387. #define EGALIB_YMAX 350
  388.  
  389. #define EGALIB_XLAST (EGA_XMAX - 1)
  390. #define EGALIB_YLAST (EGA_YMAX - 1)
  391.  
  392. #define EGALIB_VCHAR 14
  393. #define EGALIB_HCHAR 8
  394. #define EGALIB_VTIC 4
  395. #define EGALIB_HTIC 5
  396.  
  397. #include "mcega.h"
  398.  
  399. EGALIB_init()
  400. {
  401.     GPPARMS();
  402.     if (GDTYPE != 5) {
  403.         term = 0;
  404.         int_error("color EGA board not found",NO_CARET);
  405.     }
  406.     egacolor = (GDMEMORY < 256) ? ega64color : ega256color;
  407. }
  408.  
  409. EGALIB_graphics()
  410. {
  411.     graphics_on = TRUE;
  412.     GPINIT();
  413. }
  414.  
  415. EGALIB_text()
  416. {
  417.     if (graphics_on) {
  418.         graphics_on = FALSE;
  419.         pause();
  420.     }
  421.     GPTERM();
  422. }
  423.  
  424. EGALIB_linetype(linetype)
  425. {
  426.     if (linetype >= 13)
  427.         linetype %= 13;
  428.     GPCOLOR(egacolor[linetype+2]);
  429. }
  430.  
  431. EGALIB_move(x,y)
  432. {
  433.     GPMOVE(x,GDMAXROW-y);
  434. }
  435.  
  436.  
  437. EGALIB_vector(x,y)
  438. {
  439.     GPLINE(x,GDMAXROW-y);
  440. }
  441.  
  442.  
  443. EGALIB_put_text(x,y,str)
  444. int x, y;
  445. char *str;
  446. {
  447.     strcpy((char far *)buf,str);
  448.     GotoXY((int)(x/EGALIB_HCHAR),
  449.            (int)((EGALIB_YMAX-y-(EGALIB_VCHAR/2))/EGALIB_VCHAR));
  450.     gprintf(buf);
  451. }
  452.  
  453.  
  454. #define EGALIB_reset PC_reset
  455.  
  456. #endif /* EGALIB */
  457.  
  458.  
  459. #ifdef HERCULES
  460.  
  461. #define HERC_XMAX 720
  462. #define HERC_YMAX 348
  463.  
  464. #define HERC_XLAST (HERC_XMAX - 1)
  465. #define HERC_YLAST (HERC_YMAX - 1)
  466.  
  467. #define HERC_VCHAR PC_VCHAR
  468. #define HERC_HCHAR PC_HCHAR
  469. #define HERC_VTIC 4
  470. #define HERC_HTIC 5
  471.  
  472. int line_herc;
  473.  
  474. HERC_init()
  475. {
  476.     H_init();
  477. }
  478.  
  479. HERC_graphics()
  480. {
  481.     HVmode(1);
  482.     graphics_on = TRUE;
  483. }
  484.  
  485. HERC_text()
  486. {
  487.     if (graphics_on) {
  488.         graphics_on = FALSE;
  489.         pause();
  490.     }
  491.     HVmode(0);
  492. }
  493.  
  494. HERC_linetype(linetype)
  495. {
  496.     if (linetype >= 5)
  497.         linetype %= 5;
  498.     H_mask(pattern[linetype+2]);
  499.     line_herc = linetype;
  500. }
  501.  
  502. HERC_move(x,y)
  503. {
  504.     if (x < 0)
  505.         startx = 0;
  506.     else if (x > HERC_XLAST)
  507.         startx = HERC_XLAST;
  508.     else
  509.         startx = x;
  510.  
  511.     if (y < 0)
  512.         starty = 0;
  513.     else if (y > HERC_YLAST)
  514.         starty = HERC_YLAST;
  515.     else
  516.         starty = y;
  517. }
  518.  
  519. HERC_vector(x,y)
  520. {
  521.     if (x < 0)
  522.         x = 0;
  523.     else if (x > HERC_XLAST)
  524.         x = HERC_XLAST;
  525.     if (y < 0)
  526.         y = 0;
  527.     else if (y > HERC_YLAST)
  528.         y = HERC_YLAST;
  529.  
  530.     H_line(startx,HERC_YLAST-starty,x,HERC_YLAST-y);
  531.     startx = x;
  532.     starty = y;
  533. }
  534.  
  535.  
  536. HERC_put_text(x,y,str)
  537. unsigned int x, y;
  538. char *str;
  539. {
  540. int i;
  541. int line;
  542.     line= line_herc;     /* disable the dotted lines temporarily */
  543.     H_mask(pattern[0]);
  544.     switch(pc_angle) {
  545.         case 0 : y -= HERC_VCHAR/2;
  546.                 break;
  547.         case 1 : x += HERC_VCHAR/2;
  548.                 break;
  549.     }
  550.     for (i=0;str[i];i++) {
  551.         PC_putc(x,HERC_YLAST-y,str[i],pc_angle,H_line);
  552.         switch(pc_angle) {
  553.             case 0 : x+=HERC_HCHAR ;
  554.                     break;
  555.             case 1 : y+=HERC_HCHAR ;
  556.                     break;
  557.         }
  558.     }
  559.     H_mask(pattern[line]);  /* enable dotted lines */
  560. }
  561.  
  562.  
  563. #define HERC_text_angle PC_text_angle
  564.  
  565. #define HERC_reset PC_reset
  566.  
  567.  
  568. #endif /* HERCULES */
  569.  
  570.  
  571. /* thanks to sask!macphed (Geoff Coleman and Ian Macphedran) for the
  572.    ATT 6300 driver */ 
  573.  
  574.  
  575. #ifdef ATT6300
  576.  
  577. #define ATT_XMAX 640
  578. #define ATT_YMAX 400
  579.  
  580. #define ATT_XLAST (ATT_XMAX - 1)
  581. #define ATT_YLAST (ATT_YMAX - 1)
  582.  
  583. #define ATT_VCHAR PC_VCHAR
  584. #define ATT_HCHAR PC_HCHAR
  585. #define ATT_VTIC 4
  586. #define ATT_HTIC 5
  587.  
  588. #define ATT_init CGA_init
  589.  
  590. ATT_graphics()
  591. {
  592.     graphics_on = TRUE;
  593.     Vmode(0x40);        /* 40H is the magic number for the AT&T driver */
  594. }
  595.  
  596. #define ATT_text CGA_text
  597.  
  598. #define ATT_linetype CGA_linetype
  599.  
  600. #define ATT_move CGA_move
  601.  
  602. ATT_vector(x,y)
  603. {
  604.     PC_line(startx,ATT_YLAST-starty,x,ATT_YLAST-y);
  605.     startx = x;
  606.     starty = y;
  607. }
  608.  
  609.  
  610. ATT_put_text(x,y,str)
  611. unsigned int x, y;
  612. char *str;
  613. {
  614. int i;
  615. int line;
  616.     line= line_cga;     /* disable the dotted lines temporarily */
  617.     PC_mask(pattern[0]);
  618.     switch(pc_angle) {
  619.         case 0 : y -= ATT_VCHAR/2;
  620.                 break;
  621.         case 1 : x += ATT_VCHAR/2;
  622.                 break;
  623.     }
  624.     for (i=0;str[i];i++) {
  625.         PC_putc(x,ATT_YLAST-y,str[i],pc_angle,PC_line);
  626.         switch(pc_angle) {
  627.             case 0 : x+=ATT_HCHAR ;
  628.                     break;
  629.             case 1 : y+=ATT_HCHAR ;
  630.                     break;
  631.         }
  632.     }
  633.     PC_mask(pattern[line]);  /* enable dotted lines */
  634. }
  635.  
  636.  
  637. #define ATT_text_angle PC_text_angle
  638.  
  639. #define ATT_reset CGA_reset
  640.  
  641. #endif  /* ATT6300 */
  642.  
  643.  
  644. #ifdef CORONA
  645.  
  646. #define COR_XMAX 640
  647. #define COR_YMAX 325
  648.  
  649. #define COR_XLAST (COR_XMAX - 1)
  650. #define COR_YLAST (COR_YMAX - 1)
  651.  
  652. #define COR_VCHAR PC_VCHAR
  653. #define COR_HCHAR PC_HCHAR
  654. #define COR_VTIC 4
  655. #define COR_HTIC 5
  656.  
  657. int line_cor;
  658.  
  659. static int corscreen;        /* screen number, 0 - 7 */
  660.  
  661. COR_init()
  662. {
  663. register char *p;
  664.     if (!(p = getenv("CORSCREEN")))
  665.         int_error("must run CORPLOT for Corona graphics",NO_CARET);
  666.     corscreen = *p - '0';
  667. }
  668.  
  669. COR_graphics()
  670. {
  671.     graphics_on = TRUE;
  672.     Vmode(3);                /* clear text screen */
  673.     grinit(corscreen);
  674.     grandtx();
  675. }
  676.  
  677. COR_text()
  678. {
  679.     if (graphics_on) {
  680.         graphics_on = FALSE;
  681.         pause();
  682.     }
  683.     grreset();
  684.     txonly();
  685.     Vmode(3);
  686. }
  687.  
  688. COR_linetype(linetype)
  689. {
  690.     if (linetype >= 5)
  691.         linetype %= 5;
  692.     line_cor = linetype;
  693.     Cor_mask(pattern[linetype+2]);
  694. }
  695.  
  696. COR_move(x,y)
  697. {
  698.     if (x < 0)
  699.         startx = 0;
  700.     else if (x > COR_XLAST)
  701.         startx = COR_XLAST;
  702.     else
  703.         startx = x;
  704.  
  705.     if (y < 0)
  706.         starty = 0;
  707.     else if (y > COR_YLAST)
  708.         starty = COR_YLAST;
  709.     else
  710.         starty = y;
  711. }
  712.  
  713. COR_vector(x,y)
  714. {
  715.     if (x < 0)
  716.         x = 0;
  717.     else if (x > COR_XLAST)
  718.         x = COR_XLAST;
  719.     if (y < 0)
  720.         y = 0;
  721.     else if (y > COR_YLAST)
  722.         y = COR_YLAST;
  723.  
  724.     Cor_line(startx,COR_YLAST-starty,x,COR_YLAST-y);
  725.     startx = x;
  726.     starty = y;
  727. }
  728.  
  729.  
  730. COR_put_text(x,y,str)
  731. unsigned int x, y;
  732. char *str;
  733. {
  734. int i;
  735. int line;
  736.     line= line_cor;     /* disable the dotted lines temporarily */
  737.     Cor_mask(pattern[0]);
  738.     switch(pc_angle) {
  739.         case 0 : y -= COR_VCHAR/2;
  740.                 break;
  741.         case 1 : x += COR_VCHAR/2;
  742.                 break;
  743.     }
  744.     for (i=0;str[i];i++) {
  745.         PC_putc(x,COR_YLAST-y,str[i],pc_angle,Cor_line);
  746.         switch(pc_angle) {
  747.             case 0 : x+=COR_HCHAR ;
  748.                     break;
  749.             case 1 : y+=COR_HCHAR ;
  750.                     break;
  751.         }
  752.     }
  753.     COR_mask(pattern[line]);  /* enable dotted lines */
  754. }
  755.  
  756.  
  757. #define COR_text_angle PC_text_angle
  758.  
  759. #define COR_reset PC_reset
  760.  
  761. #endif /* CORONA */
  762.  
  763.  
  764. #else /* ifndef __TURBOC__ */
  765. /* all of the Turbo C routines for the different graphics devices go here */
  766.  
  767. #define VGA_XMAX 640
  768. #define VGA_YMAX 480
  769.  
  770. #define VGA_XLAST (VGA_XMAX - 1)
  771. #define VGA_YLAST (VGA_YMAX - 1)
  772.  
  773. #define VGA_VCHAR 10
  774. #define VGA_HCHAR 8
  775. #define VGA_VTIC 4
  776. #define VGA_HTIC 5
  777.  
  778. #define SVGA_XMAX 640
  779. #define SVGA_YMAX 480
  780.  
  781. #define SVGA_VCHAR 10
  782. #define SVGA_HCHAR 8
  783. #define SVGA_VTIC 4
  784. #define SVGA_HTIC 5
  785.  
  786. static int vga256color[] = {7,8,2,3,4,5,9,14,12,15,13,10,11,1,6};
  787. static int *vgacolor;
  788.  
  789. static int svga_xmax = SVGA_XMAX,
  790.        svga_ymax = SVGA_YMAX,
  791.        svga_xlast = 639,
  792.        svga_ylast = 479;
  793.  
  794. #define VGA_reset EGALIB_reset
  795. #define VGA_text EGALIB_text
  796. #define VGA_move EGALIB_move
  797. #define VGA_vector EGALIB_vector
  798. #define VGA_text_angle PC_text_angle
  799. #define VGA_justify_text PC_justify_text
  800.  
  801. #define SVGA_reset EGALIB_reset
  802. #define SVGA_text EGALIB_text
  803. #define SVGA_move EGALIB_move
  804. #define SVGA_vector EGALIB_vector
  805. #define SVGA_text_angle PC_text_angle
  806. #define SVGA_justify_text PC_justify_text
  807. #define SVGA_linetype VGA_linetype
  808.  
  809. int PC_text_angle(ang)
  810. int ang;
  811. {
  812.     int size = svga_ymax > 600 ? 2 : 1;
  813.  
  814.     pc_angle = ang;
  815.  
  816.     switch (ang) {
  817.         case 0 : settextstyle(DEFAULT_FONT,HORIZ_DIR,size);
  818.             break;
  819.         case 1 : settextstyle(DEFAULT_FONT,VERT_DIR,size);
  820.             break;
  821.     }
  822.     return TRUE;
  823. }
  824.  
  825. int PC_justify_text(mode)
  826. enum JUSTIFY mode;
  827. {
  828.     switch(mode) {
  829.         case LEFT :
  830.             settextjustify(LEFT_TEXT,CENTER_TEXT);
  831.             break;
  832.         case CENTRE :
  833.             settextjustify(CENTER_TEXT,CENTER_TEXT);
  834.             break;
  835.         case RIGHT:
  836.             settextjustify(RIGHT_TEXT,CENTER_TEXT);
  837.             break;
  838.     }
  839.     return TRUE;
  840. }
  841.  
  842. VGA_init()
  843. {
  844.     g_driver=VGA;
  845.     g_mode=2;
  846.     gettextinfo(&tinfo);
  847.         initgraph(&g_driver,&g_mode,path);
  848.         if(g_driver!=9){
  849.           term=0;
  850.           switch (g_driver){
  851.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  852.                      break;
  853.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  854.                      break;
  855.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  856.                      break;
  857.             case -5: fprintf(stderr,"Insufficient memory to load ",
  858.                              "graphics driver.");
  859.                      break;
  860.             }
  861.  
  862. /*          int_error("color VGA board not found",NO_CARET);*/
  863.         }
  864.         if(g_driver==VGA) vgacolor=vga256color;
  865. }
  866.  
  867. VGA_graphics()
  868. {       g_driver=VGA;
  869.     g_mode=2;
  870.     graphics_on = TRUE;
  871.     gettextinfo(&tinfo);
  872.     setgraphmode(getgraphmode());
  873.     VGA_justify_text(LEFT);
  874. }
  875.  
  876. VGA_linetype(linetype)
  877. {
  878.     if (linetype >= 13)
  879.         linetype %= 13;
  880.     setcolor(vgacolor[linetype+2]);
  881. }
  882.  
  883. VGA_put_text(x,y,str)
  884. unsigned int x, y;
  885. char *str;
  886. {
  887.     strcpy((char far *)buf,str);
  888.     outtextxy(x,VGA_YLAST-y,buf);
  889. }
  890.  
  891.  
  892. VGAMONO_linetype(linetype)
  893. {
  894.     if (linetype >= 5)
  895.         linetype %= 5;
  896.     setlinestyle(4,pattern[linetype+2],1);
  897. }
  898.  
  899. static int huge detect_svga(void)
  900. {
  901.     return g_mode;
  902. }
  903.  
  904. SVGA_init()
  905. {
  906.     char *p, name[128], *SVGA = getenv( "SVGA" );
  907.  
  908.     if (SVGA == NULL)
  909.         int_error("'SVGA' driver environment variable is not set",
  910.               NO_CARET);
  911.  
  912.     strcpy(name, SVGA);
  913.     if ((p = strrchr(name, '.')) == NULL ||
  914.         sscanf(&p[1], "%d", &g_mode) != 1)
  915.         int_error("'SVGA' envvar should be of the form 'name.mode'",
  916.               NO_CARET);
  917.  
  918.     *p = 0;
  919.  
  920.     installuserdriver(name, detect_svga);
  921.     gettextinfo(&tinfo);
  922.     g_driver = 0;
  923.         initgraph(&g_driver,&g_mode,path);
  924.         if(g_driver<0){
  925.           term=0;
  926.           switch (g_driver){
  927.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  928.                      break;
  929.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  930.                      break;
  931.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  932.                      break;
  933.             case -5: fprintf(stderr,"Insufficient memory to load ",
  934.                              "graphics driver.");
  935.                      break;
  936.             }
  937.  
  938.         }
  939.     else
  940.         vgacolor=vga256color;
  941.  
  942.     /* Get the screen size: */
  943.     svga_xmax = term_tbl[term].xmax = getmaxx() + 1;
  944.         svga_ymax = term_tbl[term].ymax = getmaxy() + 1;
  945.     svga_xlast = svga_xmax-1;
  946.     svga_ylast = svga_ymax-1;
  947.  
  948.     if (svga_ymax > 600) {               /* Double the tic/font sizes. */
  949.         term_tbl[term].h_char = SVGA_HCHAR * 2;
  950.         term_tbl[term].v_char = SVGA_VCHAR * 2;
  951.         term_tbl[term].h_tic = SVGA_HTIC * 2;
  952.         term_tbl[term].v_tic = SVGA_VTIC * 2;
  953.         settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
  954.      }
  955.     else
  956.         settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
  957. }
  958.  
  959. SVGA_graphics()
  960. {
  961.     graphics_on = TRUE;
  962.     gettextinfo(&tinfo);
  963.     setgraphmode(getgraphmode());
  964.     VGA_justify_text(LEFT);
  965.  
  966.         svga_ymax = getmaxy() + 1;
  967.     if (svga_ymax > 600)               /* Double the tic/font sizes. */
  968.         settextstyle(DEFAULT_FONT,HORIZ_DIR,2);
  969.     else
  970.         settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
  971. }
  972.  
  973. SVGA_put_text(x,y,str)
  974. unsigned int x, y;
  975. char *str;
  976. {
  977.     strcpy((char far *)buf,str);
  978.     outtextxy(x,svga_ylast-y,buf);
  979. }
  980.  
  981. #define MCGA_XMAX 640
  982. #define MCGA_YMAX 480
  983.  
  984. #define MCGA_XLAST (MCGA_XMAX - 1)
  985. #define MCGA_YLAST (MCGA_YMAX - 1)
  986.  
  987. #define MCGA_VCHAR 10
  988. #define MCGA_HCHAR 8
  989. #define MCGA_VTIC 4
  990. #define MCGA_HTIC 5
  991.  
  992. static int *MCGAcolor;
  993.  
  994. #define MCGA_reset EGALIB_reset
  995. #define MCGA_text EGALIB_text
  996. #define MCGA_move EGALIB_move
  997. #define MCGA_vector EGALIB_vector
  998. #define MCGA_text_angle PC_text_angle
  999. #define MCGA_justify_text PC_justify_text
  1000.  
  1001. MCGA_init()
  1002. {
  1003.     g_driver=MCGA;
  1004.     g_mode=5;
  1005.     gettextinfo(&tinfo);
  1006.         initgraph(&g_driver,&g_mode,path);
  1007.         if(g_driver!=2){
  1008.           term=0;
  1009.           switch (g_driver){
  1010.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  1011.                      break;
  1012.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  1013.                      break;
  1014.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  1015.                      break;
  1016.             case -5: fprintf(stderr,"Insufficient memory to load ",
  1017.                              "graphics driver.");
  1018.                      break;
  1019.             }
  1020.         }
  1021. }
  1022.  
  1023. MCGA_graphics()
  1024. {
  1025.     graphics_on = TRUE;
  1026.     gettextinfo(&tinfo);
  1027.     setgraphmode(getgraphmode());
  1028.     MCGA_justify_text(LEFT);
  1029. }
  1030.  
  1031.  
  1032. MCGA_put_text(x,y,str)
  1033. unsigned int x, y;
  1034. char *str;
  1035. {
  1036.     strcpy((char far *)buf,str);
  1037.     outtextxy(x,MCGA_YLAST-y,buf);
  1038. }
  1039.  
  1040.  
  1041. MCGA_linetype(linetype)
  1042. {
  1043.     if (linetype >= 5)
  1044.         linetype %= 5;
  1045.     setlinestyle(4,pattern[linetype+2],1);
  1046. }
  1047.  
  1048.  
  1049. #define EGALIB_XMAX 640
  1050. #define EGALIB_YMAX 350
  1051.  
  1052. #define EGALIB_XLAST (EGALIB_XMAX - 1)
  1053. #define EGALIB_YLAST (EGALIB_YMAX - 1)
  1054.  
  1055. #define EGALIB_VCHAR 10
  1056. #define EGALIB_HCHAR 8
  1057. #define EGALIB_VTIC 4
  1058. #define EGALIB_HTIC 5
  1059.  
  1060. static int ega64color[] =  {1,1,5,4,3,5,4,3, 5, 4, 3, 5, 4, 3,5};
  1061. static int ega256color[] = {7,8,2,3,4,5,9,14,12,15,13,10,11,1,6};
  1062.  
  1063. static int *egacolor;
  1064.  
  1065. #define EGALIB_text_angle PC_text_angle
  1066. #define EGALIB_justify_text PC_justify_text
  1067.  
  1068. EGALIB_init()
  1069. {
  1070.     g_driver=EGA;
  1071.     g_mode=1;
  1072.     gettextinfo(&tinfo);
  1073.         initgraph(&g_driver,&g_mode,path);
  1074.         if(g_driver<3 || g_driver>4){
  1075.           term=0;
  1076.           switch (g_driver){
  1077.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  1078.                      break;
  1079.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  1080.                      break;
  1081.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  1082.                      break;
  1083.             case -5: fprintf(stderr,"Insufficient memory to load ",
  1084.                              "graphics driver.");
  1085.                      break;
  1086.             }
  1087.  
  1088. /*          int_error("color EGA board not found",NO_CARET);*/
  1089.         }
  1090.         if(g_driver==EGA) egacolor=ega256color;
  1091.         if(g_driver==EGA64) egacolor=ega64color;
  1092. }
  1093.  
  1094. EGALIB_graphics()
  1095. {
  1096.     graphics_on = TRUE;
  1097.     gettextinfo(&tinfo);
  1098.     setgraphmode(getgraphmode());
  1099.     EGALIB_justify_text(LEFT);
  1100. }
  1101.  
  1102. EGALIB_text()
  1103. {
  1104.     if (graphics_on) {
  1105.         graphics_on = FALSE;
  1106.         pause();
  1107.     }
  1108.     restorecrtmode();
  1109.         textmode(tinfo.currmode);
  1110.     clrscr();
  1111.     svga_ymax = SVGA_YMAX; /* Since it may double font size if too high. */
  1112. }
  1113.  
  1114. EGALIB_linetype(linetype)
  1115. {
  1116.     if (linetype >= 13)
  1117.         linetype %= 13;
  1118.     setcolor(egacolor[linetype+2]);
  1119. }
  1120.  
  1121. EGALIB_move(x,y)
  1122. {
  1123.         moveto(x,getmaxy()-y);
  1124. }
  1125.  
  1126.  
  1127. EGALIB_vector(x,y)
  1128. {
  1129.     lineto(x,getmaxy()-y);
  1130. }
  1131.  
  1132.  
  1133. EGALIB_put_text(x,y,str)
  1134. unsigned int x, y;
  1135. char *str;
  1136. {
  1137.     strcpy((char far *)buf,str);
  1138.     outtextxy(x,EGALIB_YLAST-y,buf);
  1139. }
  1140.  
  1141.  
  1142. EGALIB_reset()
  1143. {
  1144.       closegraph();
  1145.         textmode(tinfo.currmode);
  1146.     clrscr();
  1147.     svga_ymax = SVGA_YMAX; /* Since it may double font size if too high. */
  1148. }
  1149.  
  1150.  
  1151. #define CGA_XMAX 640
  1152. #define CGA_YMAX 200
  1153.  
  1154. #define CGA_XLAST (CGA_XMAX - 1)
  1155. #define CGA_YLAST (CGA_YMAX - 1)
  1156.  
  1157. #define CGA_VCHAR 10
  1158. #define CGA_HCHAR 8
  1159. #define CGA_VTIC 4
  1160. #define CGA_HTIC 6
  1161.  
  1162. #define CGA_text_angle PC_text_angle
  1163. #define CGA_justify_text PC_justify_text
  1164. #define CGA_reset PC_reset
  1165.  
  1166. CGA_init()
  1167. {
  1168.     g_driver=CGA;
  1169.     g_mode=4;
  1170.     gettextinfo(&tinfo);
  1171.     initgraph(&g_driver,&g_mode,path);
  1172.           switch (g_driver){
  1173.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  1174.                      break;
  1175.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  1176.                      break;
  1177.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  1178.                      break;
  1179.             case -5: fprintf(stderr,"Insufficient memory to load ",
  1180.                              "graphics driver.");
  1181.                      break;
  1182.             }
  1183. /*    PC_color(1);         monochrome */
  1184.  
  1185. }
  1186.  
  1187. CGA_graphics()
  1188. {
  1189.     graphics_on = TRUE;
  1190.     gettextinfo(&tinfo);
  1191.     setgraphmode(getgraphmode());
  1192.     CGA_justify_text(LEFT);
  1193.     /*    Vmode(6);*/
  1194. }
  1195.  
  1196. #define CGA_text PC_text
  1197.  
  1198. CGA_linetype(linetype)
  1199. {
  1200.     if (linetype >= 5)
  1201.         linetype %= 5;
  1202.     setlinestyle(4,pattern[linetype+2],1);
  1203. }
  1204.  
  1205. CGA_move(x,y)
  1206. {
  1207.     moveto(x,getmaxy()-y);
  1208. }
  1209.  
  1210.  
  1211. CGA_vector(x,y)
  1212. {
  1213.     lineto(x,getmaxy()-y);
  1214. }
  1215.  
  1216. CGA_put_text(x,y,str)
  1217. unsigned int x, y;
  1218. char *str;
  1219. {
  1220.     strcpy((char far *)buf,str);
  1221.     outtextxy(x,CGA_YLAST-y,buf);
  1222. }
  1223.  
  1224.  
  1225.  
  1226. #define HERC_XMAX 720
  1227. #define HERC_YMAX 348
  1228.  
  1229. #define HERC_XLAST (HERC_XMAX - 1)
  1230. #define HERC_YLAST (HERC_YMAX - 1)
  1231.  
  1232. #define HERC_VCHAR 10
  1233. #define HERC_HCHAR 8
  1234. #define HERC_VTIC 4
  1235. #define HERC_HTIC 5
  1236.  
  1237. #define HERC_text_angle PC_text_angle
  1238. #define HERC_justify_text PC_justify_text
  1239. #define HERC_reset PC_reset
  1240.  
  1241. HERC_init()
  1242. {
  1243.     g_driver=HERCMONO;
  1244.     g_mode=0;
  1245.     gettextinfo(&tinfo);
  1246.       initgraph(&g_driver,&g_mode,path);
  1247.           switch (g_driver){
  1248.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  1249.                      break;
  1250.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  1251.                      break;
  1252.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  1253.                      break;
  1254.             case -5: fprintf(stderr,"Insufficient memory to load ",
  1255.                              "graphics driver.");
  1256.                      break;
  1257.             }
  1258. }
  1259.  
  1260. HERC_graphics()
  1261. {
  1262.     gettextinfo(&tinfo);
  1263.     setgraphmode(getgraphmode());
  1264.     HERC_justify_text(LEFT);
  1265.     graphics_on = TRUE;
  1266. }
  1267.  
  1268. HERC_text()
  1269. {
  1270.     if (graphics_on) {
  1271.         graphics_on = FALSE;
  1272.         pause();
  1273.     }
  1274.     restorecrtmode();
  1275.         textmode(tinfo.currmode);
  1276.     clrscr();
  1277. }
  1278.  
  1279. HERC_linetype(linetype)
  1280. {
  1281.     if (linetype >= 5)
  1282.         linetype %= 5;
  1283.     setlinestyle(4,pattern[linetype+2],1);
  1284. }
  1285.  
  1286. HERC_move(x,y)
  1287. {
  1288.     if (x < 0)
  1289.         x = 0;
  1290.     else if (x > HERC_XLAST)
  1291.         x = HERC_XLAST;
  1292.  
  1293.     if (y < 0)
  1294.         y = 0;
  1295.     else if (y > HERC_YLAST)
  1296.         y = HERC_YLAST;
  1297.     moveto(x,getmaxy()-y);
  1298. }
  1299.  
  1300. HERC_vector(x,y)
  1301. {
  1302.     if (x < 0)
  1303.         x = 0;
  1304.     else if (x > HERC_XLAST)
  1305.         x = HERC_XLAST;
  1306.     if (y < 0)
  1307.         y = 0;
  1308.     else if (y > HERC_YLAST)
  1309.         y = HERC_YLAST;
  1310.  
  1311.     lineto(x,getmaxy()-y);
  1312. }
  1313.  
  1314.  
  1315. HERC_put_text(x,y,str)
  1316. unsigned int x, y;
  1317. char *str;
  1318. {
  1319.     strcpy((char far *)buf,str);
  1320.     outtextxy(x,HERC_YLAST-y,buf);
  1321. }
  1322.  
  1323.  
  1324. #ifdef ATT6300
  1325. /* this driver added by rjl@monu1.cc.monash.edu.au */
  1326.  
  1327. #define ATT_XMAX 640
  1328. #define ATT_YMAX 400
  1329.  
  1330. #define ATT_XLAST (ATT_XMAX - 1)
  1331. #define ATT_YLAST (ATT_YMAX - 1)
  1332.  
  1333. #define ATT_VCHAR PC_VCHAR
  1334. #define ATT_HCHAR PC_HCHAR
  1335. #define ATT_VTIC 4
  1336. #define ATT_HTIC 5
  1337.  
  1338. #define ATT_text_angle PC_text_angle
  1339. #define ATT_justify_text PC_justify_text
  1340. #define ATT_reset PC_reset
  1341.  
  1342. ATT_init()
  1343. {
  1344.     g_driver=ATT400;
  1345.     g_mode=5;
  1346.     gettextinfo(&tinfo);
  1347.       initgraph(&g_driver,&g_mode,path);
  1348.           switch (g_driver){
  1349.             case -2: fprintf(stderr,"Graphics card not detected.\n");
  1350.                      break;
  1351.             case -3: fprintf(stderr,"BGI driver file cannot be found.\n");
  1352.                      break;
  1353.             case -4: fprintf(stderr,"Invalid BGI driver file.\n");
  1354.                      break;
  1355.             case -5: fprintf(stderr,"Insufficient memory to load ",
  1356.                              "graphics driver.");
  1357.                      break;
  1358.             }
  1359. }
  1360.  
  1361. ATT_graphics()
  1362. {
  1363.     gettextinfo(&tinfo);
  1364.     setgraphmode(getgraphmode());
  1365.     ATT_justify_text(LEFT);
  1366.     graphics_on = TRUE;
  1367. }
  1368.  
  1369. ATT_text()
  1370. {
  1371.     if (graphics_on) {
  1372.         graphics_on = FALSE;
  1373.         pause();
  1374.     }
  1375.     restorecrtmode();
  1376.         textmode(tinfo.currmode);
  1377.     clrscr();
  1378. }
  1379.  
  1380. ATT_linetype(linetype)
  1381. {
  1382.     if (linetype >= 5)
  1383.         linetype %= 5;
  1384.     setlinestyle(4,pattern[linetype+2],1);
  1385. }
  1386.  
  1387. ATT_move(x,y)
  1388. {
  1389.     if (x < 0)
  1390.         x = 0;
  1391.     else if (x > ATT_XLAST)
  1392.         x = ATT_XLAST;
  1393.  
  1394.     if (y < 0)
  1395.         y = 0;
  1396.     else if (y > ATT_YLAST)
  1397.         y = ATT_YLAST;
  1398.     moveto(x,getmaxy()-y);
  1399. }
  1400.  
  1401. ATT_vector(x,y)
  1402. {
  1403.     if (x < 0)
  1404.         x = 0;
  1405.     else if (x > ATT_XLAST)
  1406.         x = ATT_XLAST;
  1407.     if (y < 0)
  1408.         y = 0;
  1409.     else if (y > ATT_YLAST)
  1410.         y = ATT_YLAST;
  1411.  
  1412.     lineto(x,getmaxy()-y);
  1413. }
  1414.  
  1415.  
  1416. ATT_put_text(x,y,str)
  1417. unsigned int x, y;
  1418. char *str;
  1419. {
  1420.     strcpy((char far *)buf,str);
  1421.     outtextxy(x,ATT_YLAST-y,buf);
  1422. }
  1423. #endif /* ifdef ATT6300 */
  1424.  
  1425. #endif /* ifndef __TURBOC__ */
  1426.  
  1427.